﻿using System;
using System.Collections;
using System.Xml;
using Moonlite.ExtensionApi.XimlInterfaces;

namespace Moonlite.Platform.Ximl {
    public class XimlNode : IXimlNode {
        private string name;
        private IXimlNodeProperties properties = new XimlNodeProperties();
        private IXimlNode parent;
        private XmlNode innerNode;
        private object tag;
        public IXimlNode Parent {
            get { return parent; }
            set { parent = value; }
        }
        public string Guid {
            get { return properties["guid"]; }
        }
        public string this[string key] {
            get { return properties[key]; }
            set { properties[key] = value; }
        }
        public string Name {
            get { return name; }
        }
        public IXimlNodeProperties Properties {
            get { return properties; }
        }
        public object Tag {
            get { return tag; }
            set { tag = value; }
        }
        internal void ScanNode() {
            name = innerNode.Name;
            foreach (XmlAttribute attribute in innerNode.Attributes) {
                properties[attribute.Name] = attribute.Value;
            }
        }
        public override string ToString() {
            return "XimlNode: " + name;
        }
        public XimlNode() { }
        internal XimlNode(XmlNode innerNode, IXimlNode parent) {
            if (innerNode == null) {
                throw new ArgumentNullException("innerNode");
            }
            this.innerNode = innerNode;
            this.parent = parent;
            ScanNode();
        }
    }
}
